
*********************************************************

/*
Acknowledgments - We thank Marco Alfano for making his code available. 
This code uses the code provided in the Supplementary data section of 
"Daughters, dowries, deliveries: The effect of marital payments on fertility choices in India"
and can be found here: https://www.sciencedirect.com/science/article/pii/S0304387816300979#s0110

*/



*** Deck 1: prepare general information of household: 

use "$ORIGINAL/rd99001a.dta" , clear 

*********************************************
*** Dummy for deck 1 
*********************************************

ge deck1=1 

* There are 52 questions here and in the questionnaire. 

*********************************************
*** HH id: 
*********************************************

su id2
count if id2==. 

ge hh_id = id2

* See whether there are more than 1 observations with the same id:

bys hh_id: ge test_id = _N
ta test_id
drop test_id

*********************************************
*** Religion:
*********************************************

* Question 10 is about religion. Hindu=1 and Muslim=2

ta q10 
ta q10 , m nolabel

ge muslim = q10==2
ge hindu = q10!=2

ta q10 hindu
ta q10 muslim
ta q10 if hindu==1
ta q10 if muslim==1

gen religion = 1 if q10==1
replace religion = 2 if q10==2
replace religion = 3 if q10==3
replace religion = 4 if q10 ==4
replace religion = 5 if q10>4
label define religion 1 "hindu" 2 "muslim" 3 "sikh" 4 "christian" 5 "others"
label value religion religion
*********************************************
*** Caste: 
*********************************************

ta q11
ta q11 , m nolabel

ge caste_bra = q51==1
ge caste_up = q51==2
ge caste_sc = q51==3
ge caste_st = q51==4
ge caste_obc = q51==5
ge caste_nonclh = q51==6
ge caste_nonclm = q51==7
ge caste_noncls = q51==8
ge caste_nonclr = q51==9

foreach x of varlist caste_bra caste_up caste_sc caste_st caste_obc caste_nonclh caste_nonclm caste_noncls caste_nonclr {
	ta q51 `x'
	}

*********************************************
*** State:
*********************************************

* Question 8 is about the state

/*

1: AP
2: Bihar
3: Gujarat
4: Haryana
5: HP
7: Karnataka
8: Kerala
9: MP
10: Maharashtra
11: Orissa
12: Punjab
13: Rajasthan
14: TN
15: UP
16: WB
17: Assam

*/

ta state
ta state , m nolabel



*** Amendment states: 

ge amendment = 0
* Bihar
replace amendment = 1 if state==2 
* Haryana
replace amendment = 1 if state==4
* HP
replace amendment = 1 if state==5
* Punjab
replace amendment = 1 if state==12

*********************************************
*** Checks with other schedules:
*********************************************

*** In Deck 4: 
ta q19
ta q19 , m nolabel

ge peoplein_deck4 = q19

*** In Deck 6: 

ta q21
ta q21 , m nolabel

ge peoplein_deck6 = q21

*********************************************
*** Total household members
*********************************************

* Question 17 is about the total members of the household
ta n17
ta n17 , m
su n17 , d

ge hh_members = n17
count if n17==.
count if hh_members==.

*********************************************
*** Owns land: yes=1
*********************************************

* Question 25 is about ownership of land

ta q25
ta q25 ,m 
count if q25==.

ge owns_land = q25==1

ta q25 owns_land , m
ta q25 if owns_land==1 , m

*********************************************
*** Hh income
*********************************************

* Question 52 is about the household income (in 1000s of Rupees)

ta q52 
ta q52 , m nolabel
count if q52==.

ge hh_income = q52*1000
su q52 hh_income

egen state_district = group(state district)

*********************************************
*** Only keep some vars: 
*********************************************

keep id2 deck1 hindu muslim state amendment peoplein_deck4 peoplein_deck6 hh_members owns_land hh_income caste* religion state_district

*********************************************
*** Save
*********************************************

sort id2

save ddd-reds-deck1.dta, replace

*************************************************
***** Deck 2
*************************************************

u "$ORIGINAL/rd99002", clear
rename q7 head_relation 
rename q12 gender
rename q13 age
rename q14 marital_status
rename q15 education

gen deck2 = 1

//drop if women hh head
bysort id2: egen women_hh_head = total(gender==2 & head_relation==0)
bysort id2: egen totalhead = total(gender==1 & head_relation==0)
bysort id2: egen totalspouse = total(gender==2 & head_relation==3)

bysort id2: egen agehus = mean(age / (gender==1 & head_relation==0))
bysort id2: egen agewife = mean(age / (gender==2 & head_relation==3))

bysort id2: egen educhus = mean(education / (gender==1 & head_relation==0))
bysort id2: egen educwife = mean(education / (gender==2 & head_relation==3))

bysort id2: egen marrhus = mean(marital_status /(gender==1 & head_relation==0))
bysort id2: egen marrwife = mean(marital_status / (gender==2 & head_relation==3))

ge married = marrwife==1
replace married=. if marrwife==.

collapse agewife agehus educwife educhus women_hh_head totalhead totalspouse marrhus marrwife deck2 married, by(id2)

save deck2,replace 


* Dowry deck
u "$ORIGINAL/rd99008", clear

ge deck8=1 

rename q20 year_marriage
label var year_marriage "Head's year of marriage"

ge dowry_out = q41 // dowry recieved by hh head/parents = dowry paid by his wife hence out
replace dowry_out=0 if q41==1
replace dowry_out=. if q41==0
su dowry_out,d

ge dowry_in = q42 // dowry paid by hh head/parents = dowry recv by his wife hence in
replace dowry_in=0 if q42==1
replace dowry_in=. if q42==0
su dowry_in,d

gen dow_net = dowry_out - dowry_in
su dow_net,d

ge educfh = q22
ge educmh = q23
ge landh = q26

ge educfw = q29 
ge educmw = q30
ge landw = q33

label var dowry_out "Dowry recieved by head/head's parent's"
label var dowry_in "Dowry given by head/head's parent's"

global pareduc "educfh educmh educfw educmw"
global land "landh landw"

** Creating wealth index for 
** husband's and wife's family
foreach var in $pareduc {
	replace `var' = . if `var'>18
}

foreach var in $land {
	sum `var',d
	replace `var' = . if `var'>r(p99)
}

gen loglandh = log(1+landh)
gen loglandw = log(1+landw)

gen distsp = q36


global wife_wealth  "educfw loglandw"
global hus_wealth "educfh loglandh"

pca $wife_wealth, comp(1)
predict wifewealth

sum wifewealth
gen nwifewealth = (wifewealth - r(min))/(r(max) - r(min)) 




pca $hus_wealth, comp(1)
predict huswealth
sum huswealth
gen nhuswealth = (huswealth - r(min))/(r(max) - r(min))

gen landh_d = landh>0 
replace landh_d = . if landh==.

label var landh_d "Husband Family Land"

gen landw_d = landw>0 
replace landw_d = . if landw==.

label var landw_d "Wife Family Land"


keep year_marriage dowry_in dowry_out dow_net id2 deck8 educfh educmh landh educfw educmw landw nwifewealth nhuswealth distsp $wife_wealth $hus_wealth landh_d landw_d
save v1_dowry, replace

u deck2,clear
merge 1:1 id2 using v1_dowry
keep if _merge==3


keep if women_hh_head==0 // keep if head of household is a man
keep if totalhead==1 // keep if total head = 1 
keep if totalspouse==1 // keep if total spouse = 1
keep if marrhus==1 & marrwife==1 // keep if married husband and wife


gen yearbirth = 1999 - agewife
ge years_schooling = educwife
replace years_schooling=. if educwife>15
ta years_schooling , m
ta educwife if years_schooling==. , m
ta educwife if years_schooling!=. , m
* Should be the same: 
su educwife years_schooling if years_schooling!=.
su educwife years_schooling if educwife<=15
* Should be 0: 
count if years_schooling!=educwife & years_schooling!=.

*** Create dummies: 

ge primary = years_schooling>=1 & years_schooling<=4
replace primary=. if years_schooling==.
ge secondary = years_schooling>=5 & years_schooling<=15
replace secondary=. if years_schooling==. 

* Checks: 

ta years_schooling primary, m
ta years_schooling secondary, m

ta educwife primary, m
ta educwife secondary, m

ta educwife if primary==1 , m 
ta educwife if secondary==1 , m

*********************************************
*** Schooling - Spouse: 
*********************************************

* Question 14 is about schooling of spouse

ta educhus
ta educhus , m nolabel
su educhus , d

ge years_schooling_spouse = educhus
replace years_schooling_spouse =. if educhus>15
ta years_schooling_spouse , m
ta educhus if years_schooling_spouse ==. , m
ta educhus if years_schooling_spouse!=. , m
* Should be the same: 
su educhus years_schooling_spouse if years_schooling_spouse!=.
su educhus years_schooling_spouse if educhus<=15
* Should be 0:  
count if years_schooling_spouse!=educhus & years_schooling_spouse!=.

*** Create dummies: 

ge primary_spouse = years_schooling_spouse>=1 & years_schooling_spouse<=4
replace primary_spouse=. if years_schooling_spouse==.
ge secondary_spouse = years_schooling_spouse>=5 & years_schooling_spouse<=15
replace secondary_spouse=. if years_schooling_spouse==. 

* Checks: 

ta years_schooling_spouse primary_spouse , m
ta years_schooling_spouse secondary_spouse , m

ta educhus primary_spouse , m
ta educhus secondary_spouse , m

ta educhus if primary_spouse==1 , m
ta educhus if secondary_spouse==1 , m

bys id2: ge peoplein_deck2_2 = _N

replace deck8 = peoplein_deck2_2

keep id2 deck8 married year_marriage yearbirth primary secondary primary_spouse secondary_spouse dowry_out dow_net years_schooling years_schooling_spouse educfh educmh landh educfw educmw landw nwifewealth nhuswealth agewife agehus distsp $wife_wealth $hus_wealth landh_d landw_d

save deckmainwife, replace


// for endogenous regressions 

merge 1:1 id2 using ddd-reds-deck1.dta
keep if _merge==3
keep id2 hh_income years_schooling_spouse owns_land 

rename years_schooling_spouse fd_yschool
rename owns_land fd_land



save wife2data,replace



*********************************************************
*********************************************************
*********************************************************

*** Deck 8 : HH head and his wife


*** Deck 4: All sisters

use "$ORIGINAL/rd99004.dta" , clear 

*********************************************
*** Dummy for this deck
*********************************************

* There are 31 questions in the questionnaire and 31 questions here. 

ge deck4=1 

gen hsister = q31==1
gen wsister = q31==2

*********************************************
*** Year of marriage
*********************************************

* Question 10 is about the year of marriage.

ta q10
ta q10, m
count if q10==.

*** Married: 

ge married = q10!=0
replace married=. if q10==.

*** Year of marriage: 

ge year_marriage = q10

replace year_marriage=. if q10<1960
replace year_marriage=. if q10>1999

ta year_marriage , m
ta q10 if year_marriage==.
ta q10 if year_marriage!=.
* Should be the same: 
su q10 year_marriage if year_marriage!=.
* Should be missing: 
ta year_marriage if married==0, m
* Should be zero: 
count if year_marriage!=q10 & year_marriage!=.

*********************************************
*** Year of birth
*********************************************

* Question 7 is about the year of birth

ta q7
ta q7 , m nolabel
count if q7==.

ge yearbirth = q7
replace yearbirth=. if q7<1900
ta yearbirth, m
su q7 if yearbirth==.
su q7 if yearbirth!=.
count if yearbirth==.
* Should be the same: 
su q7 yearbirth if yearbirth!=.
* Should be 0: 
count if q7!=yearbirth & yearbirth!=.
count if q7!=yearbirth & q7>1900

*********************************************
*** Schooling of woman: 
*********************************************

* Question 13 is about the years of schooling

ta q13
ta q13 , m nolabel
count if q13==.

ge years_schooling = q13
replace years_schooling=. if q13>15
ta years_schooling , m
ta q13 if years_schooling==. , m
ta q13 if years_schooling!=. , m
* Should be the same: 
su q13 years_schooling if years_schooling!=.
su q13 years_schooling if q13<=15
* Should be 0: 
count if years_schooling!=q13 & years_schooling!=.

*** Create dummies: 

ge primary = years_schooling>=1 & years_schooling<=4
replace primary=. if years_schooling==.
ge secondary = years_schooling>=5 & years_schooling<=15
replace secondary=. if years_schooling==. 

* Checks: 

ta years_schooling primary, m
ta years_schooling secondary, m

ta q13 primary, m
ta q13 secondary, m

ta q13 if primary==1 , m 
ta q13 if secondary==1 , m

*********************************************
*** Schooling - Spouse: 
*********************************************

* Question 14 is about schooling of spouse

ta q14
ta q14 , m nolabel
su q14 , d

ge years_schooling_spouse = q14
replace years_schooling_spouse =. if q14>15
ta years_schooling_spouse , m
ta q14 if years_schooling_spouse ==. , m
ta q14 if years_schooling_spouse!=. , m
* Should be the same: 
su q14 years_schooling_spouse if years_schooling_spouse!=.
su q14 years_schooling_spouse if q14<=15
* Should be 0:  
count if years_schooling_spouse!=q14 & years_schooling_spouse!=.

*** Create dummies: 

ge primary_spouse = years_schooling_spouse>=1 & years_schooling_spouse<=4
replace primary_spouse=. if years_schooling_spouse==.
ge secondary_spouse = years_schooling_spouse>=5 & years_schooling_spouse<=15
replace secondary_spouse=. if years_schooling_spouse==. 

* Checks: 

ta years_schooling_spouse primary_spouse , m
ta years_schooling_spouse secondary_spouse , m

ta q14 primary_spouse , m
ta q14 secondary_spouse , m

ta q14 if primary_spouse==1 , m
ta q14 if secondary_spouse==1 , m

*********************************************
*** Dowries paid: 
*********************************************

* Question 11 is about dowry paid
* Legend: q11=1 is no dowry paid
* Legend: q11=0 means not applicable

ta q11
ta q11, m 
count if q11==.

ge dowry_out = q11
replace dowry_out=0 if q11==1
replace dowry_out=. if q11==0
su dowry_out,d

ge dowry_in = q12 // is mostly zero, zero till 90th percentile
replace dowry_in=0 if q12==1
replace dowry_in=. if q12==0
su dowry_in,d

gen dow_net = dowry_out - dowry_in
su dow_net,d


* Should be 1: 
ta q11 if dowry_out==0
* Should be 0: 
ta q11 if dowry_out==.
* should be 0: 
ta dowry_out if q11==1
* should be missing: 
ta dowry_out if q11==0 , m 
* Should be identical:  
su q11 dowry_out if q11>1
* Should be 0: 
count if q11!=dowry_out & dowry_out!=. & dowry_out!=0 & dowry_out!=1
count if q11!=dowry_out & dowry_out!=. & dowry_out>1
* Should be only 0s and 1s: 
ta q11 if dowry_out!=q11

*********************************************
*** People in this deck:
*********************************************

bys id2: ge peoplein_deck4_2 = _N

*********************************************
*** Keep only some variables: 
*********************************************

keep id2 deck4 married year_marriage yearbirth years_schooling years_schooling_spouse primary secondary primary_spouse secondary_spouse dowry_out dow_net peoplein_deck4_2 hsister wsister

*********************************************
*** Save
*********************************************

save ddd-reds-deck4.dta, replace

*********************************************************
*********************************************************
*********************************************************
*** Deck 6: All daughters

use "$ORIGINAL/rd99006.dta" , clear 

g daughter = 1
*********************************************
*** Dummy for this deck
*********************************************

* Deck 6 has 30 questions and here there are 30 vars

ge deck6=1 

*********************************************
*** Year of marriage
*********************************************

* Question 10 is about the year of marriage

ta q10
ta q10, m
count if q10==. 

ge married = q10!=0
replace married=. if q10==.

ge year_marriage = q10

// keeping marriages between 1960 and 1999

replace year_marriage=. if q10<1960
replace year_marriage=. if q10>1999
ta year_marriage , m
ta q10 if year_marriage==.
ta q10 if year_marriage!=.
* should be the same: 
su q10 year_marriage if year_marriage!=.
su q10 year_marriage if q10>=1960
* should be missing: 
ta year_marriage if married==0, m
* Should be 0: 
count if year_marriage!=q10 & q10>=1960
count if year_marriage!=q10 & year_marriage!=.

*********************************************
*** Year of birth
*********************************************

* Question 7 is about year of birth

ta q7
ta q7 , m nolabel
count if q7==.

// keeping births between 1900 and 1999

ge yearbirth = q7
replace yearbirth=. if q7<1900
replace yearbirth=. if q7>1999
ta yearbirth, m
ta q7 if yearbirth==.
ta q7 if yearbirth!=.
* Should be the same: 
su q7 yearbirth if yearbirth!=.
su q7 yearbirth if q7>=1900 & q7<=1999
* Should be zero: 
count if q7!=yearbirth & yearbirth!=.
count if q7!=yearbirth & q7>=1900 & q7<=1999

*********************************************
*** Schooling of woman: 
*********************************************

* Question 13 is about years of schooling 

ta q13
ta q13 , m nolabel
su q13 , d
count if q13==.

ge years_schooling = q13
replace years_schooling=. if q13>15
ta years_schooling , m
ta q13 if years_schooling==. , m 
ta q13 if years_schooling!=. , m
* should be the same: 
su q13 years_schooling if years_schooling!=.
su q13 years_schooling if q13<=15
* should be 0: 
count if q13!=years_schooling & years_schooling!=.
count if q13!=years_schooling & q13<=15

*** Create dummies: 

ge primary = years_schooling>=1 & years_schooling<=4
replace primary=. if years_schooling==.
ge secondary = years_schooling>=5 & years_schooling<=15
replace secondary=. if years_schooling==. 

* Checks: 

ta years_schooling primary, m
ta years_schooling secondary, m

ta q13 primary, m
ta q13 secondary, m

ta q13 if primary==1
ta q13 if secondary==1

*********************************************
*** Schooling - Spouse: 
*********************************************

* Question 14 is about years of schooling of spouse

ta q14
ta q14 , m nolabel
su q14 , d
count if q14==.

ge years_schooling_spouse = q14
replace years_schooling_spouse =. if q14>15
ta years_schooling_spouse , m
ta q14 if years_schooling_spouse==. , m 
ta q14 if years_schooling_spouse!=. , m 
* should be the same: 
su q14 years_schooling_spouse if years_schooling_spouse!=.
su q14 years_schooling_spouse if q14<=15
* should be 0: 
count if q14!= years_schooling_spouse & years_schooling_spouse!=.
count if q14!= years_schooling_spouse & q14<=15

*** Create dummies: 

ge primary_spouse = years_schooling_spouse>=1 & years_schooling_spouse<=4
replace primary_spouse=. if years_schooling_spouse==.
ge secondary_spouse = years_schooling_spouse>=5 & years_schooling_spouse<=15
replace secondary_spouse=. if years_schooling_spouse==. 

* Checks: 

ta years_schooling_spouse primary_spouse , m
ta years_schooling_spouse secondary_spouse , m

ta q14 primary_spouse , m
ta q14 secondary_spouse , m

ta q14 if primary_spouse==1
ta q14 if secondary_spouse==1

*********************************************
*** Dowries paid: 
*********************************************

* Question 11 is about dowry paid out
* Legend: q11=1 means no dowry
* Legend: q11=0 means NA

ta q11
ta q11, m 
count if q11==.

*** All dowries: 

ge dowry_out = q11
replace dowry_out=0 if q11==1
replace dowry_out=. if q11==0
su dowry_out
* Should be 1: 
ta q11 if dowry_out==0
* Should be 0: 
ta q11 if dowry_out==.
* should be 0: 
ta dowry_out if q11==1
* should be missing: 
ta dowry_out if q11==0 , m 
* Should be identical: 
su q11 dowry_out if q11>1
su q11 dowry_out if dowry_out!=. & dowry_out!=0
* Should be 0: 
count if q11!=dowry_out & dowry_out!=. & dowry_out!=0 & dowry_out!=1
count if q11!=dowry_out & dowry_out!=. & dowry_out>1
* Should be only 0s and 1s: 
ta q11 if dowry_out!=q11


ge dowry_in = q12
replace dowry_in=0 if q12==1
replace dowry_in=. if q12==0
su dowry_in,d

gen dow_net = dowry_out - dowry_in
su dow_net,d


*********************************************
*** People in this deck:
*********************************************

bys id2: ge peoplein_deck6_2 = _N

*********************************************
*** Keep only some variables: 
*********************************************

keep id2 deck6 married year_marriage yearbirth primary secondary primary_spouse secondary_spouse dowry_out dow_net peoplein_deck6_2  years_schooling years_schooling_spouse

*********************************************
*** Save
*********************************************

save ddd-reds-deck6.dta, replace

*********************************************************
*********************************************************
*********************************************************

*********************************************************
*********************************************************
*********************************************************


** Deck 3 - Brothers

use "$ORIGINAL/rd99003.dta" , clear 

g brtohers = 1
*********************************************
*** Dummy for this deck
*********************************************

* Deck 3 has 30 questions and here there are 30 vars

ge deck3=1 

*********************************************
*** Year of marriage
*********************************************

* Question 10 is about the year of marriage

ta q10
ta q10, m
count if q10==. 

ge married = q10!=0
replace married=. if q10==.

ge year_marriage = q10

* Question 7 is about the year of birth of Brother/ Father! (different)

ta q7
ta q7 , m nolabel
count if q7==.

ge yearbirth_bro = q7
replace yearbirth_bro=. if q7<1900
ta yearbirth_bro, m
su q7 if yearbirth_bro==.
su q7 if yearbirth_bro!=.
count if yearbirth_bro==.
* Should be the same: 
su q7 yearbirth_bro if yearbirth_bro!=.
* Should be 0: 
count if q7!=yearbirth_bro & yearbirth_bro!=.
count if q7!=yearbirth_bro & q7>1900




*********************************************
*** Schooling of woman: 
*********************************************

* Question 13 is about years of schooling 

ta q14
ta q14 , m nolabel
su q14 , d
count if q14==.

ge years_schooling = q14
replace years_schooling=. if q14>15
ta years_schooling , m
ta q14 if years_schooling==. , m 
ta q14 if years_schooling!=. , m
* should be the same: 
su q14 years_schooling if years_schooling!=.
su q14 years_schooling if q14<=15
* should be 0: 
count if q14!=years_schooling & years_schooling!=.
count if q14!=years_schooling & q14<=15

*** Create dummies: 

ge primary = years_schooling>=1 & years_schooling<=4
replace primary=. if years_schooling==.
ge secondary = years_schooling>=5 & years_schooling<=15
replace secondary=. if years_schooling==. 

* Checks: 

ta years_schooling primary, m
ta years_schooling secondary, m

ta q14 primary, m
ta q14 secondary, m

ta q14 if primary==1
ta q14 if secondary==1

*********************************************
*** Schooling - Spouse: man
*********************************************

* Question 14 is about years of schooling of spouse

ta q13
ta q13 , m nolabel
su q13 , d
count if q13==.

ge years_schooling_spouse = q13
replace years_schooling_spouse =. if q13>15
ta years_schooling_spouse , m
ta q13 if years_schooling_spouse==. , m 
ta q13 if years_schooling_spouse!=. , m 
* should be the same: 
su q13 years_schooling_spouse if years_schooling_spouse!=.
su q13 years_schooling_spouse if q13<=15
* should be 0: 
count if q13!= years_schooling_spouse & years_schooling_spouse!=.
count if q13!= years_schooling_spouse & q13<=15

*** Create dummies: 

ge primary_spouse = years_schooling_spouse>=1 & years_schooling_spouse<=4
replace primary_spouse=. if years_schooling_spouse==.
ge secondary_spouse = years_schooling_spouse>=5 & years_schooling_spouse<=15
replace secondary_spouse=. if years_schooling_spouse==. 

* Checks: 

ta years_schooling_spouse primary_spouse , m
ta years_schooling_spouse secondary_spouse , m

ta q13 primary_spouse , m
ta q13 secondary_spouse , m

ta q13 if primary_spouse==1
ta q13 if secondary_spouse==1


*********************************************
** Dowries paid: Note: Since this is for brothers 
** and we are creating questions 
** WRT t girl dowry_recv code as dowry given
*********************************************

* Question 11 is about dowry paid out
* Legend: q11=1 means no dowry
* Legend: q11=0 means NA

ta q12
ta q12, m 
count if q12==.

*** All dowries: 

ge dowry_out = q12
replace dowry_out=0 if q12==1
replace dowry_out=. if q12==0
su dowry_out
* Should be 1: 
ta q12 if dowry_out==0
* Should be 0: 
ta q12 if dowry_out==.
* should be 0: 
ta dowry_out if q12==1
* should be missing: 
ta dowry_out if q12==0 , m 
* Should be identical: 
su q12 dowry_out if q12>1
su q12 dowry_out if dowry_out!=. & dowry_out!=0
* Should be 0: 
count if q12!=dowry_out & dowry_out!=. & dowry_out!=0 & dowry_out!=1
count if q12!=dowry_out & dowry_out!=. & dowry_out>1
* Should be only 0s and 1s: 
ta q12 if dowry_out!=q12


ge dowry_in = q11
replace dowry_in=0 if q11==1
replace dowry_in=. if q11==0
su dowry_in,d

gen dow_net = dowry_out - dowry_in
su dow_net,d


*********************************************
*** People in this deck:
*********************************************

bys id2: ge peoplein_deck3_2 = _N

*********************************************
*** Keep only some variables: 
*********************************************

keep id2 deck3 married year_marriage yearbirth_bro  primary secondary primary_spouse secondary_spouse dowry_out dow_net peoplein_deck3_2  years_schooling years_schooling_spouse

*********************************************
*** Save
*********************************************

save ddd-reds-deck3.dta, replace


*** Sons, code same say as brothers


** Deck 5 - Sons

use "$ORIGINAL/rd99005.dta" , clear 

g sons = 1
*********************************************
*** Dummy for this deck
*********************************************

* Deck 3 has 30 questions and here there are 30 vars

ge deck5=1 

*********************************************
*** Year of marriage
*********************************************

* Question 10 is about the year of marriage

ta q10
ta q10, m
count if q10==. 

ge married = q10!=0
replace married=. if q10==.

ge year_marriage = q10

ge yearbirth_son = q7
replace yearbirth_son=. if q7<1900
ta yearbirth_son, m
su q7 if yearbirth_son==.
su q7 if yearbirth_son!=.
count if yearbirth_son==.
* Should be the same: 
su q7 yearbirth_son if yearbirth_son!=.
* Should be 0: 
count if q7!=yearbirth_son & yearbirth_son!=.
count if q7!=yearbirth_son & q7>1900




*********************************************
*** Schooling of woman: 
*********************************************

* Question 13 is about years of schooling 

ta q14
ta q14 , m nolabel
su q14 , d
count if q14==.

ge years_schooling = q14
replace years_schooling=. if q14>15
ta years_schooling , m
ta q14 if years_schooling==. , m 
ta q14 if years_schooling!=. , m
* should be the same: 
su q14 years_schooling if years_schooling!=.
su q14 years_schooling if q14<=15
* should be 0: 
count if q14!=years_schooling & years_schooling!=.
count if q14!=years_schooling & q14<=15

*** Create dummies: 

ge primary = years_schooling>=1 & years_schooling<=4
replace primary=. if years_schooling==.
ge secondary = years_schooling>=5 & years_schooling<=15
replace secondary=. if years_schooling==. 

* Checks: 

ta years_schooling primary, m
ta years_schooling secondary, m

ta q14 primary, m
ta q14 secondary, m

ta q14 if primary==1
ta q14 if secondary==1

*********************************************
*** Schooling - Spouse: man
*********************************************

* Question 14 is about years of schooling of spouse

ta q13
ta q13 , m nolabel
su q13 , d
count if q13==.

ge years_schooling_spouse = q13
replace years_schooling_spouse =. if q13>15
ta years_schooling_spouse , m
ta q13 if years_schooling_spouse==. , m 
ta q13 if years_schooling_spouse!=. , m 
* should be the same: 
su q13 years_schooling_spouse if years_schooling_spouse!=.
su q13 years_schooling_spouse if q13<=15
* should be 0: 
count if q13!= years_schooling_spouse & years_schooling_spouse!=.
count if q13!= years_schooling_spouse & q13<=15

*** Create dummies: 

ge primary_spouse = years_schooling_spouse>=1 & years_schooling_spouse<=4
replace primary_spouse=. if years_schooling_spouse==.
ge secondary_spouse = years_schooling_spouse>=5 & years_schooling_spouse<=15
replace secondary_spouse=. if years_schooling_spouse==. 

* Checks: 

ta years_schooling_spouse primary_spouse , m
ta years_schooling_spouse secondary_spouse , m

ta q13 primary_spouse , m
ta q13 secondary_spouse , m

ta q13 if primary_spouse==1
ta q13 if secondary_spouse==1


*********************************************
*** Dowries paid: Note: 
** Since this is for brothers and we are 
** creating questions WRT girl dowry_recv code as dowry given
*********************************************

* Question 11 is about dowry paid out
* Legend: q11=1 means no dowry
* Legend: q11=0 means NA

ta q12
ta q12, m 
count if q12==.

*** All dowries: 

ge dowry_out = q12
replace dowry_out=0 if q12==1
replace dowry_out=. if q12==0
su dowry_out
* Should be 1: 
ta q12 if dowry_out==0
* Should be 0: 
ta q12 if dowry_out==.
* should be 0: 
ta dowry_out if q12==1
* should be missing: 
ta dowry_out if q12==0 , m 
* Should be identical: 
su q12 dowry_out if q12>1
su q12 dowry_out if dowry_out!=. & dowry_out!=0
* Should be 0: 
count if q12!=dowry_out & dowry_out!=. & dowry_out!=0 & dowry_out!=1
count if q12!=dowry_out & dowry_out!=. & dowry_out>1
* Should be only 0s and 1s: 
ta q12 if dowry_out!=q12


ge dowry_in = q11
replace dowry_in=0 if q11==1
replace dowry_in=. if q11==0
su dowry_in,d

gen dow_net = dowry_out - dowry_in
su dow_net,d


*********************************************
*** People in this deck:
*********************************************

bys id2: ge peoplein_deck5_2 = _N

*********************************************
*** Keep only some variables: 
*********************************************

keep id2 deck5 married year_marriage yearbirth_son  primary secondary primary_spouse secondary_spouse dowry_out dow_net peoplein_deck5_2  years_schooling years_schooling_spouse

*********************************************
*** Save
*********************************************

save ddd-reds-deck5.dta, replace


/*

** Note: 

For main anaylsis, decks used are 4,6 and 8,
that is sisters, daughters and household head 
and his wife. We do additional analysis with brothers and
sons datasets appended, the results are qualitatively
unchaged. 

*/


** Start appending: 

*** Start with deck 4: 

use ddd-reds-deck4.dta , clear 

*** Append decks 4 and 6: 

count 
append using ddd-reds-deck6.dta

*** Append deck 8: 
count
append using deckmainwife


*** Generate dummies for 

ge deck=.
foreach n of numlist 4 6 8 {
	replace deck=`n' if deck`n'==1
	}
ta deck , m

*********************************************************
*********************************************************
*********************************************************
*** Merge with household (deck 1)

sort id2

merge m:1 id2 using ddd-reds-deck1.dta
ta _merge

* 216 could not be merged. These are households with no daughters (deck 6) or sisters (deck 4)

su peoplein_deck4 peoplein_deck6 if _merge==2
tab1 peoplein_deck4 peoplein_deck6 if _merge==2

* Drop 216 households without daughters or sisters: 
count
keep if _merge==3
count
drop _merge
*** Number of individuals in each dataset should be the same: 

su peoplein_deck4 peoplein_deck4_2 if deck4==1 
su peoplein_deck4 peoplein_deck4_2 if peoplein_deck4_2!=. 
count if peoplein_deck4!=peoplein_deck4_2 & deck4==1

su peoplein_deck6 peoplein_deck6_2 if deck6==1
su peoplein_deck6 peoplein_deck6_2 if peoplein_deck6_2!=.
count if peoplein_deck6!=peoplein_deck6_2 & deck6==1


// keep if married
keep if married==1

sort year_marriage id2

// merge with deflate data
merge m:1 year_marriage using deflatedow


// 1999 dowries
gen dow99 = cpi99*dowry_out

gen downet_99 = cpi99*dow_net

order id2 _merge deck year_marriage dowry_out dow99 downet_99 dow_net cpi99

ta year_marriage , m 
ta year_marriage if married==0 , m 
ta year_marriage if married==1 , m 
count
keep if married==1
keep if year_marriage<=1999
count

*********************************************
*** Women born between 1920 and 1984
		*** SAMPLE SELECTION  ****
*********************************************

//count
ta yearbirth , m 
keep if yearbirth>=1920 & yearbirth<=1984
//count


*********************************************
*** DD terms: 
*********************************************

*** Post

ge post = year_marriage>=1986
ge post_yob = yearbirth>=1968

*** Interaction

ge post_hindu = hindu*post
ge post_hindu_yob = hindu*post_yob


*********************************************
*** Save the Main data for analysis
*********************************************

save ddd-reds_withmain.dta , replace 





/*

** Secondary Data sets creation 

This version of the data contains additional
information regarding the wife's and 
husband's family - land holding and
parental education 

*/




*********************************************
*** Wealth different data create
*********************************************

u ddd-reds-deck6.dta, clear

merge m:1 id2 using wife2data
keep if _merge==3
bysort id2: gen ndaughters = _N

** For daughters of hh head
sum hh_income,d 
replace hh_income = . if hh_income>r(p99)

gen linc = log(1+hh_income)


global daughters "linc fd_land fd_yschool"

pca $daughters, comp(1)
predict dwealth

sum dwealth
gen ndwealth = (dwealth - r(min))/(r(max) - r(min)) 

bysort id2: egen nndwealth = mean(ndwealth)
bysort id2: egen father_educ = mean(fd_yschool)
bysort id2: egen owns_land_d = mean(fd_land)

keep id2 deck6 married year_marriage yearbirth primary secondary primary_spouse secondary_spouse dowry_out dow_net peoplein_deck6_2  years_schooling years_schooling_spouse nndwealth ndaughters father_educ owns_land_d

save ddd-reds-deck6_v2.dta,replace


*** Append: (version 2 of data with wealth)

*** Start with deck 4: 

use ddd-reds-deck4.dta , clear 

*** Append decks 4 and 6: 

count 
append using ddd-reds-deck6_v2.dta

*** Append deck 8: 
count
append using deckmainwife


*** Generate dummies for 

ge deck=.
foreach n of numlist 4 6 8 {
	replace deck=`n' if deck`n'==1
	}
ta deck , m

*********************************************************
*********************************************************
*********************************************************
*** Merge with household (deck 1)

sort id2

merge m:1 id2 using ddd-reds-deck1.dta
ta _merge

* 216 could not be merged. These are households with no daughters (deck 6) or sisters (deck 4)

su peoplein_deck4 peoplein_deck6 if _merge==2
tab1 peoplein_deck4 peoplein_deck6 if _merge==2

* Drop 216 households without daughters or sisters: 
count
keep if _merge==3
count
drop _merge
*** Number of individuals in each dataset should be the same: 

su peoplein_deck4 peoplein_deck4_2 if deck4==1 
su peoplein_deck4 peoplein_deck4_2 if peoplein_deck4_2!=. 
count if peoplein_deck4!=peoplein_deck4_2 & deck4==1

su peoplein_deck6 peoplein_deck6_2 if deck6==1
su peoplein_deck6 peoplein_deck6_2 if peoplein_deck6_2!=.
count if peoplein_deck6!=peoplein_deck6_2 & deck6==1


// keep if married
keep if married==1

sort year_marriage id2

// merge with deflate data
merge m:1 year_marriage using deflatedow

//gen dow_2015 = ( dowry_out*100 ) / cpi

// 1999 dowries
gen dow99 = cpi99*dowry_out

gen downet_99 = cpi99*dow_net

order id2 _merge year_marriage dowry_out dow99 downet_99 dow_net cpi99

ta year_marriage , m 
ta year_marriage if married==0 , m 
ta year_marriage if married==1 , m 
count
keep if married==1
keep if year_marriage<=1999
count

*********************************************
*** Women born between 55 and 75
		*** SAMPLE SELECTION  ****
*********************************************

//count
ta yearbirth , m 
keep if yearbirth>=1920 & yearbirth<=1984
//count


*********************************************
*** DD terms: 
*********************************************

*** Post

ge post = year_marriage>=1986
ge post_yob = yearbirth>=1968

*** Interaction

ge post_hindu = hindu*post
ge post_hindu_yob = hindu*post_yob

bysort id2: egen nww = mean(nwifewealth)
bysort id2: egen nwh = mean(nhuswealth)

bysort id2: egen fheduc = mean(educfh)
bysort id2: egen fweduc = mean(educfw)

bysort id2: egen fland = mean(landh_d)
bysort id2: egen wland = mean(landw_d)




gen wealth = . 
replace wealth = nww if deck8==1
replace wealth = nndwealth if deck6==1
replace wealth = nww if wsister==1
replace wealth = nwh if hsister==1

gen feduc = .
replace feduc = fweduc if deck8==1
replace feduc = father_educ if deck6==1
replace feduc = fweduc if wsister==1
replace feduc = fheduc if hsister == 1

gen landown = .
replace landown = wland if deck8==1
replace landown = owns_land_d if deck6==1
replace landown = fland if wsister==1
replace landown = wland if hsister==1

label var feduc "Father Education"
label var landown "Natal Family Owns Land"

*********************************************
*** Save 
*********************************************

save ddd-reds_withmain_v2.dta , replace 


/*

This final version of the data also contains

dowry information on brothers and borther-in-laws

as a robustness check 

*/



*** Append: 

*** Start with deck 4: 

use ddd-reds-deck4.dta , clear 

*** Append decks 4 and 6: 

count 
append using ddd-reds-deck6.dta

*** Append deck 3: 
count
append using ddd-reds-deck3.dta

*** Append deck 5: 
count
append using ddd-reds-deck5.dta

*** Append deck 8: 
count
append using deckmainwife



*** Generate dummies for 

ge deck=.
foreach n of numlist 3 4 5 6 8 {
	replace deck=`n' if deck`n'==1
	}
ta deck , m

*********************************************************

*** Merge with household (deck 1)

sort id2

merge m:1 id2 using ddd-reds-deck1.dta
ta _merge

* 216 could not be merged. These are households with no daughters (deck 6) or sisters (deck 4)

su peoplein_deck4 peoplein_deck6 if _merge==2
tab1 peoplein_deck4 peoplein_deck6 if _merge==2

* Drop 216 households without daughters or sisters: 
count
keep if _merge==3
count
drop _merge
*** Number of individuals in each dataset should be the same: 

su peoplein_deck4 peoplein_deck4_2 if deck4==1 
su peoplein_deck4 peoplein_deck4_2 if peoplein_deck4_2!=. 
count if peoplein_deck4!=peoplein_deck4_2 & deck4==1

su peoplein_deck6 peoplein_deck6_2 if deck6==1
su peoplein_deck6 peoplein_deck6_2 if peoplein_deck6_2!=.
count if peoplein_deck6!=peoplein_deck6_2 & deck6==1


// keep if married
keep if married==1

sort year_marriage id2

// merge with deflate data
merge m:1 year_marriage using deflatedow

//gen dow_2015 = ( dowry_out*100 ) / cpi

// 1999 dowries
gen dow99 = cpi99*dowry_out

gen downet_99 = cpi99*dow_net

order id2 _merge year_marriage dowry_out dow99 downet_99 dow_net cpi99

ta year_marriage , m 
ta year_marriage if married==0 , m 
ta year_marriage if married==1 , m 
count
keep if married==1
keep if year_marriage<=1999
count

*********************************************
*** Women born between 55 and 75
		*** SAMPLE SELECTION  ****
*********************************************

//count
ta yearbirth , m 
keep if (yearbirth>=1920 & yearbirth<=1984) | (yearbirth_bro>=1920 & yearbirth_bro<=1975) |  (yearbirth_son>=1920 & yearbirth_son<=1975)
//count


*********************************************
*** DD terms: 
*********************************************

*** Post

ge post = year_marriage>=1986
ge post_yob = yearbirth>=1968

*** Interaction

ge post_hindu = hindu*post
ge post_hindu_yob = hindu*post_yob


*********************************************
*** Save 
*********************************************

save ddd-reds_withbrosons.dta , replace 





